package com.qf.lja.service;

import com.qf.lja.dao.AddrDao;
import com.qf.lja.enity.Address;
import com.qf.lja.enity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;


@WebServlet(urlPatterns = "/address")
public class AddrService extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");

        Integer userId = user.getUserId();

        AddrDao addrDao = new AddrDao();
        List<Address> addrList = addrDao.selectAddr(userId);

        req.setAttribute("addrList", addrList);
        req.getRequestDispatcher("/self_info.jsp").forward(req, resp);
    }

}
